package com.example.demo.listener;

import com.mybatisflex.annotation.SetListener;

public class AccountPermissionListener implements SetListener {
    @Override
    public Object onSet(Object entity, String property, Object value) {
        System.out.println("AccountPermissionListener");
        // 只有张三有权限
        if (isPassword(property)) {
            // 当前用户
            // String currUser = "李四";
            String currUser = "张三";
            boolean hasPermission = hasPermission(currUser);
            if (hasPermission) {
                return value;
            }
            return null;
        }
        // 别忘记返回其他属性的值
        return value;
    }

    public boolean isPassword(String property) {
        return "password".equals(property);
    }

    public boolean hasPermission(String property) {
        return "张三".equals(property);
    }
}
